﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ECONTACT.DataLayer
{
    public class DiemData
    {
        DataService m_DiemData = new DataService();

        public DataTable LayDsDiem()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM DIEM");
            m_DiemData.Load(cmd);
            return m_DiemData;
        }

        public String LuuDiem(String MaHS, String MaLop, String MaMonHoc, String MaHocKy, String Diem, String NhanXet)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("sp_NhapDiem");

                cmd.Parameters.Add("@MaHS", SqlDbType.NVarChar).Value = MaHS;
                cmd.Parameters.Add("@MaLop", SqlDbType.NVarChar).Value = MaLop;
                cmd.Parameters.Add("@MaMH", SqlDbType.NVarChar).Value = MaMonHoc;
                cmd.Parameters.Add("@MaHK", SqlDbType.NVarChar).Value = MaHocKy;
                cmd.Parameters.Add("@Diem", SqlDbType.Float).Value = Convert.ToDouble(Diem);
                cmd.Parameters.Add("@NhanXet", SqlDbType.NVarChar).Value = NhanXet;

                m_DiemData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return "Success";
        }

        public String UpdateDiem(String MaHS, String MaLop, String MaMonHoc, String MaHocKy, String Diem, String NhanXet)
        {
            try
            {
                SqlCommand cmd = new SqlCommand("sp_CapNhatDiem");

                cmd.Parameters.Add("@MaHS", SqlDbType.NVarChar).Value = MaHS;
                cmd.Parameters.Add("@MaLop", SqlDbType.NVarChar).Value = MaLop;
                cmd.Parameters.Add("@MaMH", SqlDbType.NVarChar).Value = MaMonHoc;
                cmd.Parameters.Add("@MaHK", SqlDbType.NVarChar).Value = MaHocKy;
                cmd.Parameters.Add("@SoDiemCongOrTru", SqlDbType.Float).Value = Convert.ToDouble(Diem); // diem cong hoac tru
                cmd.Parameters.Add("@NhanXet", SqlDbType.NVarChar).Value = NhanXet;

                m_DiemData.LoadProc(cmd);
            }
            catch (System.Exception ex)
            {
                return ex.Message;
            }
            return "Success";
        }
        
        public DataTable XemDiem(String MaHS)
        {
            DataService m_DData = new DataService();
            SqlCommand cmd = new SqlCommand("sp_XemDiemHS");

            cmd.Parameters.Add("@MaHS", SqlDbType.Int).Value = Convert.ToInt32(MaHS);

            m_DData.LoadProc(cmd);
            return m_DData;
        }
        //public void XemDiem(String MaHS)
        //{
        //    SqlCommand cmd = new SqlCommand("sp_XemDiemHS");

        //    cmd.Parameters.Add("@MaHS", SqlDbType.NVarChar).Value = MaHS;

        //    m_DiemData.LoadProc(cmd);
        //}

    }
}
